﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ElasticSearchTest.Model
{
    public class GroupCount
    {
        public string SearchWord { get; set; }
        public long? TotalCount { get; set; }


        public GroupCount()
        {

        }

        public static GroupCount Parse(string csvLine)
        {
            if (csvLine is null)
            {
                return null;
            }

            var arr = csvLine.Split(',');
            if (arr is null)
            {
                return null;
            }

            if (arr.Length > 1)
            {
                return new GroupCount()
                {
                    SearchWord = arr[0],
                    TotalCount = long.Parse(arr[1])
                };
            }
            else if (arr.Length > 0)
            {
                return new GroupCount()
                {
                    SearchWord = arr[0],
                    TotalCount = 0
                };
            }
            return null;
        }
    }
}
